    <%@page import="model.Benutzer"%>
    <%@page import="model.Immobilie"%>
    <%@page import="java.util.ArrayList"%>
    <%@page import="java.util.HashMap"%>
    <%--
        Document   : index
        Created on : Jan 29, 2014, 6:58:38 PM
        Author     : markraus
    --%>
     
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML>
     
    <html>
            <head>
                    <title>Immobilienhandel</title>
                    <meta charset="utf-8">
                    <meta name="author" content="Marcel Krause & Edgar Julca" />
                    <meta name="description" content="Immobilienhandel mit JavaServlets" />
                    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
     
                    <link rel="stylesheet" type="text/css" href="css/style.css" />
                    <link rel="shortcut icon" href="css/icon.ico">
                    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300' rel='stylesheet' type='text/css'>
                    <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
                    
                    <script src="js/jquery-1.10.2.min.js"></script>
                    <script src="js/lightbox-2.6.min.js"></script>
                    <link href="css/lightbox.css" rel="stylesheet" />
            </head>
            <%
                int id = 0;
                Immobilie imb = new Immobilie();
                Benutzer verkaeufer = new Benutzer();
                Benutzer benutzer = (Benutzer) session.getAttribute("Benutzer");
                
                if(request.getParameter("id")!=null){
                     String idd = request.getParameter("id");
                     id = Integer.parseInt(idd);
                } 
                
                if(id==0)
                    response.sendRedirect("index.jsp"); 
                else{
                    ArrayList<Immobilie> immobilienListe = new ArrayList<Immobilie>();
                    if(session.getAttribute("ImmobilienListe")!=null){
                        immobilienListe = (ArrayList<Immobilie>) session.getAttribute("ImmobilienListe");
                            for(int i=0;i<immobilienListe.size();i++){
                                if(immobilienListe.get(i).getI_id() == id){
                                    imb = immobilienListe.get(i);
                                }
                            }
                            if(imb==null){
                                response.sendRedirect("traumhaus.html"); 
                            }
                            
                    }
                    else{
                        response.sendRedirect("index.jsp"); 
                    }  
                    
                    HashMap<String,Benutzer> benutzerListe = new HashMap<String,Benutzer>();
                    if(session.getAttribute("BenutzerListe")!=null){
                        benutzerListe = (HashMap<String,Benutzer>) session.getAttribute("BenutzerListe");
                        if(imb.getFk_b_id()>benutzerListe.size())
                            response.sendRedirect("index.jsp"); 
                        else{
                            for(String key : benutzerListe.keySet())
                            {
                                if(benutzerListe.get(key).getId() == imb.getFk_b_id()){
                                    verkaeufer = benutzerListe.get(key);
                                }
                            }
                        }
                    }
                    else{
                        response.sendRedirect("index.jsp"); 
                    }  
                    
                    
                    
                    if(benutzer.getId() != verkaeufer.getId()){
                        response.sendRedirect("index.jsp"); 
                    }
                }
                
            %>
            <body>
                    <header>
                        <div id="con">
                            <a name="top"></a>
                            <h1 class="home"><a href="index.jsp">Verteilte Immobilien</a></h1>
                            <%
                                
                                if(benutzer == null) //Benutzer ist nicht angemeldet
                                {
                                    
                            %>
                            <div id="header_rechts">
                                <a href="login.jsp">Einloggen</a>
                                <a href="register.jsp">Registrieren</a>
                               
                            </div>
                            <%
                            }
                            else    //Benutzer ist bereits angemeldet
                            {
                                int rolleint = benutzer.getRolle();
                                String rolle = "";
                                if(rolleint==1)
                                    rolle = "Makler";
                                else if(rolleint==2)
                                    rolle = "Käufer";
                                else if(rolleint==3)
                                    rolle = "Verkäufer";
                            %>
                            <div id="header_rechts">
                                <a><%=rolle%></a>
                                <a href="benutzer.jsp"><%=benutzer.getName()%></a>  
                            </div>
                            <%
                            }
                            %>
                        </div>
                    </header>
                        <div id="content">
       
                            <div id="container">
                               
                                <div id="immo_bilder">
                                    
                                    <a href="<%=imb.getBilder()[0]%>" data-lightbox="roadtrip"><img src="<%=imb.getBilder()[0]%>"></a>
                                    <a href="<%=imb.getBilder()[1]%>" data-lightbox="roadtrip"><img src="<%=imb.getBilder()[1]%>"></a>
                                    <a href="<%=imb.getBilder()[2]%>" data-lightbox="roadtrip"><img src="<%=imb.getBilder()[2]%>"></a>
                                    <a href="<%=imb.getBilder()[0]%>" data-lightbox="roadtrip"><img src="<%=imb.getBilder()[3]%>"></a>
                                    <a href="<%=imb.getBilder()[4]%>" data-lightbox="roadtrip"><img src="<%=imb.getBilder()[4]%>"></a>
                                    <a href="<%=imb.getBilder()[5]%>" data-lightbox="roadtrip"><img src="<%=imb.getBilder()[5]%>"></a>
                                    
                                    </div>
                                
                                <div class="immo_block">
                                    <form action="ControllerServlet" method="POST">
                                    <input type="text" class="immo_edit_titel" name="titel" value="<%=imb.getTitel()%>" onfocus="if(this.value == '<%=imb.getTitel()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getTitel()%>'; }">
                                    <div class="immo_field" style="height:150px">
                                        <div class="immo_icon">
                                        <div class="icon_links"><i class="fa fa-eur fa-5x"></i></div>
                                        </div>
                                        <div class="immo_info">
                                            <div class="immo_tabl">
                                                <b>Kaltmiete:</b>
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit_bold" name="preis" value="<%=imb.getPreis()%>0" onfocus="if(this.value == '<%=imb.getPreis()%>0') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getPreis()%>0'; }">€
                                            </div>

                                            <div class="immo_tabl">
                                                Nebenkosten:
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit" name="nebenkosten" value="<%=imb.getNebenkst()%>0" onfocus="if(this.value == '<%=imb.getNebenkst()%>0') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getNebenkst()%>0'; }">€
                                            </div>
                                            
                                             <div class="immo_tabl">
                                                Kaution:
                                            </div>
                                            <div class="immo_tabr">
                                               <input type="text" class="immo_edit" name="kaution" value="<%=imb.getKaution()%>0" onfocus="if(this.value == '<%=imb.getKaution()%>0') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getKaution()%>0'; }">€
                                            </div>
                                            
                                             <div class="immo_tabl">
                                                Provision:
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit" name="provision" value="<%=imb.getProvision()%>0" onfocus="if(this.value == '<%=imb.getProvision()%>0') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getProvision()%>0'; }">€
                                            </div>

                                            <div class="immo_tabl">
                                                <b>Gesamtmiete:</b>
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit_bold" name="schmock" value="<%=imb.getPreis()+imb.getNebenkst()%>0" onfocus="if(this.value == '<%=imb.getPreis()+imb.getNebenkst()%>0') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getPreis()+imb.getNebenkst()%>0'; }">€
                                            </div>
                                        </div>
                                </div>
                                    
                                    <div class="immo_field">
                                        <div class="immo_icon">
                                        <div class="icon_links"><i class="fa fa-home fa-5x"></i></div>
                                        </div>
                                        <div class="immo_info">
                                            <div class="immo_tabl">
                                                Zimmer:
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit" name="zimmer" value="<%=imb.getZimmer_anz()%>" onfocus="if(this.value == '<%=imb.getZimmer_anz()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getZimmer_anz()%>'; }">
                                            </div>

                                            <div class="immo_tabl">
                                                Wohnfläche ca.:
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit" name="flaeche" value="<%=imb.getWohnfl()%>" onfocus="if(this.value == '<%=imb.getWohnfl()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getWohnfl()%>'; }">m²
                                            </div>

                                            <div class="immo_tabl">
                                                Schlafzimmer:
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit" name="schlafzimmer" value="<%=imb.getSchlafz()%>" onfocus="if(this.value == '<%=imb.getSchlafz()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getSchlafz()%>'; }">
                                            </div>

                                            <div class="immo_tabl">
                                                Badezimmer:
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit" name="badezimmer" value="<%=imb.getBadezimmer()%>" onfocus="if(this.value == '<%=imb.getBadezimmer()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getBadezimmer()%>'; }">
                                            </div>

                                            <div class="immo_tabl">
                                                Bezugsfrei ab:
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit" name="bezugsfrei" value="<%=imb.getBezugsfrei()%>" onfocus="if(this.value == '<%=imb.getBezugsfrei()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getBezugsfrei()%>'; }">
                                            </div>

                                            <div class="immo_tabl">
                                                Balkon / Terasse:
                                            </div>
                                            <div class="immo_tabr">
                                                <select class="immo_edit_select" name="balkon">
                                                    <option value="true" <%if(imb.getBalkon()){%>selected="selected"<%}%>>vorhanden</option>
                                                    <option value="false" <%if(!imb.getBalkon()){%>selected="selected"<%}%>>nicht vorhanden</option>       
                                                </select>
                                            </div>

                                            <div class="immo_tabl">
                                                Garten:
                                            </div>
                                            <div class="immo_tabr">
                                                <select class="immo_edit_select" name="garten">
                                                    <option value="true" <%if(imb.getGarten()){%>selected="selected"<%}%>>vorhanden</option>
                                                    <option value="false" <%if(!imb.getGarten()){%>selected="selected"<%}%>>nicht vorhanden</option>      
                                                </select>
                                            </div>

                                            <div class="immo_tabl">
                                                Keller:
                                            </div>
                                            <div class="immo_tabr">
                                                <select class="immo_edit_select" name="keller">
                                                    <option value="true" <%if(imb.getKeller()){%>selected="selected"<%}%>>vorhanden</option>
                                                    <option value="false" <%if(!imb.getKeller()){%>selected="selected"<%}%>>nicht vorhanden</option>    
                                                </select>
                                            </div>

                                        </div>
                                    </div>
                                            
                                            
                                     <div class="immo_field" style="height:150px">
                                        <div class="immo_icon">
                                        <div class="icon_links"><i class="fa fa-map-marker fa-5x"></i></div>
                                        </div>
                                        <div class="immo_info">
                                            <div class="immo_tabl">
                                                <b>Stadt:</b>
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit_bold" name="ort" value="<%=imb.getOrt()%>" onfocus="if(this.value == '<%=imb.getOrt()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getOrt()%>'; }">
                                            </div>

                                            <div class="immo_tabl">
                                                PZL:
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit" name="plz" value="<%=imb.getPlz()%>" onfocus="if(this.value == '<%=imb.getPlz()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getPlz()%>'; }">
                                            </div>
                                            
                                             <div class="immo_tabl">
                                                Straße:
                                            </div>
                                            <div class="immo_tabr">
                                                <input type="text" class="immo_edit_small1" name="strasse" value="<%=imb.getStrasse()%>" onfocus="if(this.value == '<%=imb.getStrasse()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getStrasse()%>'; }">
                                                <input type="text" class="immo_edit_small2" name="nummer" value="<%=imb.getNr()%>" onfocus="if(this.value == '<%=imb.getNr()%>') { this.value = ''; }" onblur="if(this.value=='') { this.value='<%=imb.getNr()%>'; }">
                                            </div>
                                        </div>
                                    </div>
                                            
                                    <div class="immo_field">
                                            <div class="immo_icon">
                                                <div class="icon_links"><i class="fa fa-check fa-5x"></i></div>
                                            </div>
                                            <div class="immo_info">
                                                <br>
                                               <input type="hidden" name="immo_id" value="<%=imb.getI_id()%>">
                                    <input type="submit" class="red" style="margin-top:0px;margin-right:80px;width:130px;height:36px;"name="submit" value="Loeschen">	
                                         
                                    <input type="hidden" name="immo_id" value="<%=imb.getI_id()%>">
                                    <input type="submit" class="green" style="margin-top:0px;margin-right:20px;width:130px;height:36px;" name="submit" value="Speichern">	
                                                <br>
                                                <br>
                                            </div>
                                        </div>
                                    
                                    </form>
                                </div>
                                
                                
                                <div class="immo_block">
                                    <h2>Kontakt</h2>
                                    <div class="immo_field" style="height:150px">
                                        <div class="immo_icon">
                                        <div class="icon_links"><i class="fa fa-user fa-5x"></i></div>
                                        </div>
                                        <div class="immo_info">
                                            <div class="immo_tabl">
                                                Vorname:
                                            </div>
                                            <div class="immo_tabr">
                                                <%=verkaeufer.getVorname()%>
                                            </div>

                                            <div class="immo_tabl">
                                                Nachname:
                                            </div>
                                            <div class="immo_tabr">
                                                <%=verkaeufer.getNachname()%>
                                            </div>

                                            <div class="immo_tabl">
                                                Tel.:
                                            </div>
                                            <div class="immo_tabr">
                                                <%=verkaeufer.getTel_nr()%>
                                            </div>

                                            <div class="immo_tabl">
                                                Handy:
                                            </div>
                                            <div class="immo_tabr">
                                                <%=verkaeufer.getHand_nr()%>
                                            </div>

                                            <div class="immo_tabl">
                                                Email:
                                            </div>
                                            <div class="immo_tabr">
                                                <%=verkaeufer.getEmail()%>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                
          
                                <div id="immo_platzhalter">
                                    
                                </div>
                            </div>
        
                        </div>

                       
     
               
               
               
                    <footer>
                        <div id="con">
                            <a href="">Kontakt</a>
                            <a href="">Impressum</a>
                        </div>
                    </footer>
            </body>
    </html>

